package com.bjsj.pro.base.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjsj.pro.R;


/**
 * 类 描 述:title 类 名 称:NetworkLayout 所属包名 :com.yd.widget.showview 创 建 人:Nevermore
 */

public class TitleBarLayout extends RelativeLayout {
    private View rootView;
    private LinearLayout ll_title_bar_lefe, ll_title_bar_right, ll_title_bar_center;
    private TextView tv_title_bar_content, tv_base_title_bar_lefe, tv_base_title_bar_right;
    private ImageView iv_base_title_bar_lefe, iv_base_title_bar_righet;
    private LinearLayout lltitle;
    public TitleBarLayout(Context context) {
        this(context, null);
    }

    public TitleBarLayout(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public TitleBarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init();

    }

    private void init() {
        rootView = LayoutInflater.from(getContext()).inflate(R.layout.view_me_title_bar, null);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        addView(rootView, params);

        lltitle=(LinearLayout)rootView.findViewById(R.id.ll_title);
        // 中间
        ll_title_bar_center = (LinearLayout) rootView.findViewById(R.id.ll_title_bar_center);
        // 左边
        ll_title_bar_lefe = (LinearLayout) rootView.findViewById(R.id.ll_title_bar_lefe);
        // 右边
        ll_title_bar_right = (LinearLayout) rootView.findViewById(R.id.ll_title_bar_right);
        // 标题
        tv_title_bar_content = (TextView) rootView.findViewById(R.id.tv_title_bar_content);
        tv_base_title_bar_lefe = (TextView) rootView.findViewById(R.id.tv_base_title_bar_lefe);
        tv_base_title_bar_right = (TextView) rootView.findViewById(R.id.tv_base_title_bar_right);
        iv_base_title_bar_lefe = (ImageView) rootView.findViewById(R.id.iv_base_title_bar_lefe);
        iv_base_title_bar_righet = (ImageView) rootView.findViewById(R.id.iv_base_title_bar_righet);


        ll_title_bar_lefe.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mOnLefeListener != null) {
                    mOnLefeListener.onLefeLinstener();
                }
            }
        });
        ll_title_bar_right.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mOnRightListener != null) {
                    mOnRightListener.onRightListener();
                }

            }
        });

        ll_title_bar_center.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnCenterListener != null) {
                    mOnCenterListener.onCenterListener();
                }

            }
        });

    }
//  中间设置gone



    // 设置标题
    public void setTitle(String content) {
        if (TextUtils.isEmpty(content) || content == null) {
            tv_title_bar_content.setText("");
        } else {
            tv_title_bar_content.setText(content);
        }
    }


    public void setbgcolor(int color){
        lltitle.setBackgroundColor(color);
    }
/*    public void setRightDrawable(){
        Drawable drawable = getResources().getDrawable(R.drawable.ic_beijing);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv_title_bar_content.setCompoundDrawables(null, null, drawable, null);
        tv_title_bar_content.setCompoundDrawablePadding(10);//距离
}*/
    // 设置左边返回布局是否显示出来
    public void setLefeShow(boolean isTag, int image, String text) {
        if (isTag) {
            ll_title_bar_lefe.setVisibility(View.VISIBLE);
            if (image != 0) {
                iv_base_title_bar_lefe.setVisibility(View.VISIBLE);
                iv_base_title_bar_lefe.setImageResource(image);
            }
            if (!TextUtils.isEmpty(text)) {
                tv_base_title_bar_lefe.setVisibility(View.VISIBLE);
                tv_base_title_bar_lefe.setText(text);
            }
        } else {
            ll_title_bar_lefe.setVisibility(View.INVISIBLE);
        }
    }

    // 设置右边布局是否显示出来
    public void setRightShow(boolean isTag, int image, String text) {
        if (isTag) {
            ll_title_bar_right.setVisibility(View.VISIBLE);
            if (image != 0) {
                iv_base_title_bar_righet.setVisibility(View.VISIBLE);
                iv_base_title_bar_righet.setImageResource(image);
            }
            if (!TextUtils.isEmpty(text)) {
                tv_base_title_bar_right.setVisibility(View.VISIBLE);
                tv_base_title_bar_right.setText(text);
            }
        } else {
            ll_title_bar_right.setVisibility(View.INVISIBLE);
        }
    }


    public OnLefeListener mOnLefeListener;
    public OnRightListener mOnRightListener;
    private OnCenterListener mOnCenterListener;

    public void setmOnCenterListener(OnCenterListener mOnCenterListener) {
        this.mOnCenterListener = mOnCenterListener;
    }

    public void setmOnLefeListener(OnLefeListener mOnLefeListener) {
        this.mOnLefeListener = mOnLefeListener;
    }

    public void setmOnRightListener(OnRightListener mOnRightListener) {
        this.mOnRightListener = mOnRightListener;
    }

    public interface OnLefeListener {
        void onLefeLinstener();

    }

    public interface OnRightListener {
        void onRightListener();

    }

    public interface OnCenterListener {
        void onCenterListener();

    }

}
